package com.scsj.supermarket.presenter;

import android.content.Context;
import android.util.Log;

import com.scsj.supermarket.base.TreasureBase;
import com.scsj.supermarket.bean.TreasureBean;
import com.scsj.supermarket.model.TreasureModel;

import dkmvp.mvp.BasePresenter;
import dkmvp.net.ResponseCallback;

/**
 * 基础presenter 实现示例
 */

public class TreasurePresenter extends BasePresenter implements TreasureBase.IPresenter {

    private TreasureBase.IModel mmodel;
    private TreasureBase.IView mview;

    public TreasurePresenter(TreasureBase.IView view) {
        mview = view;
        mmodel = new TreasureModel();
    }

    @Override
    public void deliverList(Context context, String token) {

        addSubscription(mmodel.getData(context, token, new ResponseCallback<TreasureBean>() {
            @Override
            public void onSuccess(TreasureBean result) {

                if (result.getStatusCode()==200) {
                    mview.showSuccessMsg("获取成功");
                } else {
                    mview.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mview.showErrorMsg(msg);
                Log.e("onFaild", msg + "");
            }
        }));

    }
}
